package com.service;/**
 * @program: SmbmsDemo
 * @description: 订单接口实现层
 * @author: Mr.Kang
 * @create: 2020-06-01 11:08
 **/

import com.mapper.BillDao;
import com.pojo.Bill;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import sun.rmi.runtime.Log;

import javax.annotation.Resource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * @Description:
 * @author 康康真滴暖
 * @date 2020-06-01 11:08
 */

@Service
public class BillServiceImpl implements BillService {
    private Logger log= LogManager.getLogger(BillServiceImpl.class);
    @Resource
    private BillDao billDao;

    @Override
    public int add(Bill bill) throws Exception {
        int count=billDao.add(bill);
        try {
            if (count> 0){
                log.info("新增成功");
            }else {
                log.info("新增失败");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }

    @Override
    public List<Bill> getBillList(Bill bill) throws Exception {
        List<Bill> billList = null;
        try {
            billList = billDao.getBillList(bill);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return billList;
    }

    @Override
    public int deleteBillById(String delId) throws Exception {
       int count=billDao.deleteBillById(delId);
        try {
            if(count> 0){
                log.info("删除成功");
            }else {
                log.info("删除失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }

    @Override
    public Bill getBillById(String id) throws Exception {
        Bill bill = null;
        try{
            bill = billDao.getBillById(id);
        }catch (Exception e) {
            e.printStackTrace();
            bill = null;
        }
        return bill;
    }

    @Override
    public int modify(Bill bill) throws Exception {
        int count=billDao.modify(bill);
        try {
            if(count> 0){
                log.info("修改成功");
            }else {
                log.info("修改失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }
}
